package br.com.admin.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import br.com.admin.dao.DataSourceDAO;
import br.com.admin.domain.DataSource;

@Service
@Transactional
public class DataSourceService {

	@Autowired
	private DataSourceDAO dao;	
	
	public void createDataSource(DataSource entity){
		dao.save(entity);
	}
	
	public void saveOrUpdateDataSource(DataSource entity){
		dao.merge(entity);
	}
	
	public void removeDataSource(int id){
		dao.remove(DataSource.class, id);
	}
	
	public DataSource getDataSource(int id){
		return DataSource.class.cast(dao.find(DataSource.class, id));
	}

	@Transactional(readOnly=true)
	public List<DataSource> listForDataTable(List<String> searchColumns, String searchValue, String orderColumn, String orderDirection, int firstPosition, int numberOfRecords){
		return dao.listForDataTable(searchColumns, searchValue, orderColumn, orderDirection, firstPosition, numberOfRecords);
	}
	
	@Transactional(readOnly=true)
	public Long countForDataTable(List<String> searchColumns, String searchValue){
		return dao.countForDataTable(searchColumns, searchValue);
	}
}
